home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / feel0_89.lha / Feel / Modules / schemedefs.em < prev    next >
Lisp/Scheme  |  1993-07-13  |  19KB  |  845 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2.  
  3. ; newschemedef.em
  4. ; Full Scheme definition module
  5. ; DDeR
  6. ; Last change
  7. ; Sat Nov 24 15:29:39 GMT 1990
  8.  
  9. ; NB This file is written in EuLisp.  Beware that some Scheme
  10. ; functions are visible as they are renamed on import, others 
  11. ; because they are defined here, but they shouldn't be used!  
  12. ; In principle, the renaming can occur on export.
  13.  
  14. ; BUGS:
  15. ; characters module not imported, when it is the functions don't exist
  16. ; mapcar doesn't exist
  17.  
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19.  
  20. (defmodule schemedefs
  21.  
  22.   (;(import characters)
  23.  
  24.            ; Broken now...
  25.  
  26.    (except (error 
  27.         memq read read-char peek-char    ; for V0.37
  28.         let
  29.         substring string vector string-append
  30.         char-upcase char-downcase vector write-char
  31.         last-pair
  32.         let string vector do map
  33.         ) 
  34.        (rename (
  35.             ;; NB new names are exported at the end of this module
  36.             ;;(characterp char?)                not exported in V0.37
  37.             ;;(functionp procedure?)            missing in V0.37
  38.             (character-to-integer char->integer) ; wrong name in V0.37
  39.             (char-equal char=?)
  40.             (char< char<?)
  41.             (char> char>?)
  42.             (char<= char<=?)
  43.             (char>= char>=?)
  44.             (char-upcase feel-char-upcase)
  45.             (char-downcase feel-char-downcase)
  46.                     ;(character->integer char->integer)            ; instead
  47.             (consp pair?)
  48.             (symbolp symbol?)
  49.             (stringp string?)
  50.             (vectorp vector?)
  51.             (numberp number?)
  52.             (eq eq?) 
  53.             (equal equal?) 
  54.             (evenp even?)
  55.             (integer-to-character integer->char) ; wrong name in V0.37
  56.                     ;(integer->character integer->char)            ; instead
  57.                     ;(labels letrec) Bogus!!!
  58.             (last-pair last)    ; broken on improper lists in V7.04
  59.                     ;(list-length length)
  60.                     ;(list-to-string list->string)
  61.                     ;(mapcar map)
  62.             (negativep negative?)
  63.             (null null?)
  64.             (nconc append!)
  65.                     ;(number-to-string number->string)         missing in V0.37
  66.             (oddp odd?)             
  67.             (output-stream-p output-port?)
  68.             (positivep positive?)
  69.             (prin display)
  70.             (standard-input-stream current-input-port)
  71.             (standard-output-stream current-output-port)
  72.             (string-append feel-string-append)
  73.                     ;(string-slice substring)    already called substring in V0.37
  74.             (substring feel-substring)
  75.             (symbol-name symbol->string)
  76.             (make-symbol string->symbol)
  77.             (write-char feel-write-char)
  78.             (zerop zero?)
  79.  
  80.                     ; these are name clashes and so we prefix them with eulisp-
  81.  
  82.             (error eulisp-error)
  83.  
  84.                     ; these are V0.37 misfeatures
  85.  
  86.             (memq old-memq)    ;            misfeature in V0.37
  87.             (read old-read)    ;            misfeature in V0.37
  88.             (read-char old-read-char) ;        misfeature in V0.37
  89.             (peek-char old-peek-char) ;        misfeature in V0.37
  90.  
  91.             )
  92.            characters eulisp0)))
  93.  
  94.   ()
  95.  
  96. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MACROS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  97.  
  98.  
  99.   (defmacro iterate (name binds . body)
  100.     `(labels
  101.        ((,name ,(mapcar (lambda (x) (car x)) binds) ,@body))
  102.        (,name ,@(mapcar (lambda (x) (cadr x)) binds))))
  103.  
  104.   (defmacro let (binds . body)
  105.     (if (symbol? binds)
  106.       `(iterate ,binds ,@body)
  107.       `((lambda ,(map car binds) ,@body)
  108.     ,@(map cadr binds))))
  109.  
  110.   (defmacro case (key . clauses)
  111.     (let ((keyvar '@case-keyvar@))
  112.       `(let ((,keyvar ,key))
  113.      (cond
  114.       ,@(map
  115.          (lambda (clause)
  116.            (let ((op (car clause))
  117.              (rest (cdr clause)))
  118.          (cond
  119.           ((eq? op 'else) clause)
  120.           (else
  121.            (let ((items (if (pair? op) op (list op))))
  122.              `((or ,@(map (lambda (th)
  123.                        `(eqv? ',th ,keyvar))
  124.                      items))
  125.                ,@rest))))))
  126.          clauses)))))
  127.  
  128.   (defmacro letrec (binds . body)
  129.     `(let ,(map 
  130.          (lambda (bind) 
  131.            `(,(car bind) '()))
  132.          binds)
  133.        ,@(map
  134.        (lambda (bind)
  135.          `(set! ,(car bind) ,@(cdr bind)))
  136.        binds)
  137.        ,@body))
  138.  
  139.   (defun filter (pred l)
  140.     (cond
  141.       ((null l) '())
  142.       ((pred (car l)) (cons (car l) (filter pred (cdr l))))
  143.       (t (filter pred (cdr l)))))
  144.         
  145.   (defmacro do (binds condn . body)
  146.     (let ((constant (filter (lambda (bind) (= (length bind) 2)) binds))
  147.       (stepped (filter (lambda (bind) (= (length bind) 3)) binds)))
  148.       `(let ,constant
  149.      (let do-loop 
  150.           ,(map 
  151.          (lambda (bind) (list (car bind) (cadr bind)))
  152.          stepped)
  153.        (if ,(car condn) (begin ,@(cdr condn))
  154.          (begin
  155.            ,@body
  156.            (do-loop 
  157.          ,@(map (lambda (bind) (caddr bind)) stepped))))))))
  158.  
  159.   (export let iterate case letrec labels do)
  160.  
  161.   (deflocal map mapcar)
  162.  
  163.   (export mapcar)
  164.  
  165. ;;;;;;;;;;;;;;;;;;;;; PATCH SECTION for V0.37 ;;;;;;;;;;;;;;;;;;;;;;;;;
  166.  
  167. (defun open-unschemed-input-file (file)
  168.   (popen (format () "/opt/home/kjp/Bin/unscheme < ~a" file) 'input t))
  169.  
  170. (export open-unschemed-input-file)
  171.  
  172. (deflocal *true* t)
  173. (deflocal *false* '())
  174.  
  175. (export *true* *false*)
  176.  
  177. (defun eqv? (x y)
  178.   (or (eq? x y)
  179.       (and (characterp x) (characterp y) (eq? x y))
  180.       (and (number? x) (number? y) (= x y))))
  181.  
  182. (export eqv?)
  183. (export negative?)
  184.  
  185. (defun sorry dummy 
  186.   (eulisp-error "Sorry - unimplemented EuLisp function" schemedef-error))
  187.  
  188. ; These are in EuLisp but are missing in V0.37
  189.  
  190. ; (defun functionp (x) (eq (class-of x) function))
  191. ;(defun characterp (x) (eq (class-of x) character))
  192.  
  193.  
  194. ;(defun abs (x) (if (< x 0) (- x) x))
  195.  
  196. (defun expt (b n)
  197.   (cond ((= n 0)   1)
  198.         ((evenp n) ((lambda (x) (* x x)) (exp b (/ n 2))))
  199.         (t         (* b (exp b (- n 1))))))
  200.  
  201. (defun number-to-string (n . radix)
  202.   (unless (null? radix)
  203.     (display "number-to-string: ignoring radix\n"))
  204.   (format nil "~a" n))
  205.  
  206. ;(defconstant lcm sorry)
  207. ;(defconstant exp sorry)
  208. ;(defconstant tan sorry)
  209. ;(defconstant log sorry)
  210. ;(defconstant asin sorry)
  211. ;(defconstant acos sorry)
  212. ;(defconstant atan sorry)
  213.  
  214. (defconstant numerator sorry)
  215. (defconstant denominator sorry)
  216.  
  217. ; These are in EuLisp but have misfeatures in V0.37
  218.  
  219. ; (defun oddp (x) (not (evenp x)))
  220.  
  221. (defun memq (item x)        
  222.   (cond ((null x) '())
  223.         ((eq? item (car x)) x)
  224.         (t (memq item (cdr x)))))
  225.  
  226. (defun reduce (f args)
  227.   (if (null (cdr args))
  228.       (car args)
  229.       (f (car args) 
  230.      (reduce f (cdr args)))))
  231.  
  232. (defmacro make-stream-optional (name f)
  233.   `(defun ,name port
  234.      (,f (if port (car port) (standard-input-stream)))))
  235.  
  236. (make-stream-optional read     old-read)
  237. (make-stream-optional read-char old-read-char)
  238. (make-stream-optional peek-char old-peek-char)
  239.  
  240. ; Do renamings that couldn't be done above
  241.  
  242. (defconstant char? characterp)
  243. (defconstant procedure? functionp)
  244. (defconstant number->string number-to-string)
  245.  
  246. (defun substring (s i j)
  247.   (feel-substring s i (- j 1)))
  248.  
  249. (defun string-append-aux (strings)
  250.   (if (null? strings) ""
  251.     (feel-string-append (car strings) (string-append-aux (cdr strings)))))
  252.  
  253. (defun string-append strings
  254.   (string-append-aux strings))
  255.  
  256. (deflocal *case-diff* (- (char->integer #\a) (char->integer #\A)))
  257.  
  258. (defun char-upcase (x)
  259.   (cond
  260.     ((not (char-alphabetic-p x)) x)
  261.     ((char-upper-case-p x) x)
  262.     (else
  263.       (integer->char (- (char->integer x) *case-diff*)))))
  264.  
  265. (defun char-downcase (x)
  266.   (cond
  267.     ((not (char-alphabetic-p x)) x)
  268.     ((char-lower-case-p x) x)
  269.     (else
  270.       (integer->char (+ (char->integer x) *case-diff*)))))
  271.  
  272. (defun eof-object? (x) 
  273.   (eq? x *eof*))
  274.  
  275. ;(defconstant substring string-slice)    already renamed in V0.37
  276.  
  277. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  278.  
  279. ; Herald for this module appears here
  280.  
  281. (format t "Full Scheme module (development version).\n")
  282.  
  283. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  284.  
  285. ; Conditions
  286.  
  287. (defcondition scheme-error ())
  288. (defcondition schemedef-error ())
  289.  
  290. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  291. ;;;                                                          ;;;
  292. ;;;    D   E   F   I   N   I   T   I   O   N   S            ;;;
  293. ;;;                                                          ;;;
  294. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  295.  
  296. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  297.  
  298. ; define
  299.  
  300. (defun walk-body (body)
  301.   (if body
  302.       (if (and (pair? (car body))
  303.                (equal? (caar body) 'define))
  304.           (cons (list (if (pair? (cadar body))
  305.                           (car (cadar body))
  306.                           (cadar body))
  307.                       ''unassigned)
  308.                 (walk-body (cdr body)))
  309.           (walk-body (cdr body)))
  310.       nil))
  311.  
  312. ;; Broken!!!
  313.  
  314. '(defmacro define (bind . values)
  315.   (if (pair? bind)
  316.       (let ((name (car bind))
  317.         (args (cdr bind)))
  318.        (if (symbol? name)
  319.            `(progn (setq ,name
  320.                  (let ,(walk-body values)
  321.                   (lambda ,args ,@ values)))
  322.                ',name)
  323.            (eulisp-error "define: bad syntax" schemedef-error)))
  324.       (if (symbol? bind)
  325.       (if values
  326.           (if (and (pair? (car values))
  327.                (equal? (caar values) 'lambda))
  328.           `(progn (setq ,bind
  329.                 (let ,(walk-body (cddr (car values)))
  330.                      ,(car values)))
  331.               ',bind)
  332.           `(progn (setq ,bind ,(car values))
  333.               ',bind))
  334.           `(progn (setq ,bind 'unassigned) 
  335.               ',bind))
  336.       (eulisp-error "define: bad identifier" schemedef-error))))
  337.  
  338. ;; Fixed!!
  339.  
  340. (defmacro define (bind . values)
  341.   (if (pair? bind)
  342.       (let ((name (car bind))
  343.         (args (cdr bind)))
  344.        (if (symbol? name)
  345.            `(progn (setq ,name
  346.                  (lambda ,args 
  347.                    (let ,(walk-body values)
  348.                  ,@values)))
  349.                ',name)
  350.            (eulisp-error "define: bad syntax" schemedef-error)))
  351.       (if (symbol? bind)
  352.       (if values
  353.           (if (and (pair? (car values))
  354.                (equal? (caar values) 'lambda))
  355.           `(progn (setq ,bind
  356.                 (let ,(walk-body (cddr (car values)))
  357.                      ,(car values)))
  358.               ',bind)
  359.           `(progn (setq ,bind ,(car values))
  360.               ',bind))
  361.           `(progn (setq ,bind 'unassigned) 
  362.               ',bind))
  363.       (eulisp-error "define: bad identifier" schemedef-error))))
  364.  
  365. ; letd is a let which understands local defines
  366.  
  367. (defmacro letd (bind . body)
  368.   (let ((bindings (walk-body body)))
  369.        (if bindings
  370.        `(let ,bindings
  371.          (let ,bind ,@body))
  372.        `(let ,bind ,@body))))
  373.  
  374. (export letd)
  375.  
  376. (defmacro set! (bind val) `(setq ,bind ,val))
  377. (defmacro begin forms `(progn ,@forms))
  378.  
  379. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  380.  
  381. ; Streams
  382.  
  383. (defconstant the-empty-stream nil)
  384.  
  385. (defmacro cons-stream (a b) `(cons ,a (delay ,b)))
  386.  
  387. (defun head (s) (car s))
  388.  
  389. (defun tail (s) (force (cdr s)))
  390.  
  391. (defun force (promise) (promise))
  392.  
  393. (defun empty-stream? (s) (eq? s the-empty-stream))
  394.  
  395. (defmacro freeze (form) `(lambda () ,form))
  396.  
  397. (defmacro delay (form) `(make-promise (freeze ,form)))
  398.  
  399. (defun make-promise (p)
  400.   (let ((run-flag nil) (value nil))
  401.        (lambda ()
  402.            (if run-flag
  403.            value
  404.            (progn (setq run-flag t)
  405.               (setq value (p)))))))
  406. ; hack
  407.  
  408. (defconstant else t) 
  409.  
  410. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  411.  
  412. ; Simple ones
  413.  
  414. (defun inc (x) (+ x 1))    ; replaces 1+
  415. (defun dec (x) (- x 1))    ; replaces -1+
  416.  
  417. ; in V0.37, (equal? nil 'nil) is false
  418. (defun boolean? (x) (if (or (eq? x t) (eq? x nil) (eq? x 'nil)) t nil))
  419.  
  420. (defun error (message value)
  421.   (eulisp-error message scheme-error 'error-value value))
  422.  
  423. ; we assume that EuLisp mapcar evaluates in order (though Scheme 
  424. ; mapcar doesn't have to)
  425. (defmacro for-each (proc . lists) 
  426.   `(progn (mapcar ,proc ,@lists) t))
  427.  
  428. (defconstant set-car! (setter car))
  429. (defconstant set-cdr! (setter cdr))
  430. (defconstant string-set! (setter string-ref))
  431. (defconstant vector-set! (setter vector-ref))
  432.  
  433. (defun call-with-current-continuation (f) (let/cc k (f k)))
  434.  
  435. (defun list? (l)
  436.   (if (null l)
  437.       t
  438.       (if (pair? l)
  439.       (list? (cdr l))
  440.       nil)))
  441.  
  442. ; files
  443.  
  444. (defun open-input-file (filename) (open filename 'input t))
  445. (defun open-output-file (filename) (open filename 'output t))
  446. (defun close-input-port (port) (close port))
  447. (defun close-output-port (port) (close port))
  448.  
  449. ;; Don't have enough streams functions to do this.
  450. (defun input-port? (x)
  451.   t)
  452.  
  453. (defun output-port? (x)
  454.   t)
  455.  
  456. ; BTW how do these interact with signals, call/cc etc?
  457. (defun call-with-input-file (filename f)
  458.   (let ((port (open filename 'input)) (value '()))
  459.        (setq value (f port))
  460.        (close port)
  461.        value))
  462.  
  463. (defun call-with-output-file (filename f)
  464.   (let ((port (open filename 'output)) (value '()))
  465.        (setq value (f port))
  466.        (close port)
  467.        value))
  468.  
  469. (defun with-input-from-file (file thunk)
  470.   (let ((old-stream standard-input-stream))
  471.        (let ((new-stream (open filename 'input)) (value))
  472.         ((setter standard-input-stream) new-stream)
  473.         (set! value (thunk))
  474.         (close new-stream)
  475.         ((setter standard-input-stream) old-stream)
  476.         value)))
  477.  
  478. (defun with-output-to-file (file thunk)
  479.   (let ((old-stream standard-output-stream))
  480.        (let ((new-stream (open filename 'output)) (value))
  481.         ((setter standard-output-stream) new-stream)
  482.         (set! value (thunk))
  483.         (close new-stream)
  484.         ((setter standard-output-stream) old-stream)
  485.         value)))
  486.  
  487. (defun char-ready? port
  488.   (stream-ready-p (if port (car port) (standard-input-stream))))
  489.  
  490. ; type predicates
  491.  
  492. (defun integer? (x) (eq? (class-of x) integer))
  493. (defun real? (x) (eq? (class-of x) real))
  494. (defun rational? (x) (eq? (class-of x) rational))
  495. (defun complex? (x) (eq? (class-of x) complex))
  496.  
  497. ;(defun string? (x) (eq? (class-of x) string))
  498. ;(defun symbol? (x) (eq? (class-of x) symbol))
  499. ;(defun vector? (x) (eq? (class-of x) vector))
  500. ;(defun pair? (x) (eq? (class-of x) pair))
  501. ;(defun number? (x) (subclassp (class-of x) number))
  502.  
  503. (defun list->string (l)
  504.   (let ((str (make-string (length l))))
  505.     (let loop ((l l) (i 0))
  506.       (unless (null? l)
  507.         (string-set! str i (car l))
  508.     (loop (cdr l) (+ i 1))))
  509.     str))
  510.  
  511. (defun string->list (s)
  512.   (let ((len (length s)))
  513.     (let loop ((i 0))
  514.       (if (= i len) '()
  515.     (cons (string-ref s i) (loop (+ 1 i)))))))
  516.  
  517. (defun string args
  518.   (list->string args))
  519.  
  520. (deflocal list->vector (converter (class-of #(1))))
  521. (deflocal vector->list (converter (class-of '(1))))
  522.  
  523. (defun vector stuff
  524.   (list->vector stuff))
  525.  
  526. ; Still have these to define...
  527.  
  528. ; assv
  529. ; case
  530. ; catch and throw
  531. ; char-upcase etc
  532. ; do
  533. ; memv
  534. ; rationalize
  535. ; string stuff (including string, string->number)
  536. ; transcript
  537. ; vector stuff (including vector)
  538.  
  539. (defun memv (a l) (member? a l eqv?))
  540. (defun assv (a l) (assq a l))
  541.  
  542. (export memv assv)
  543.  
  544. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  545. ;;;                                                          ;;;
  546. ;;;    E    X    P    O    R    T    S                      ;;;
  547. ;;;                                                          ;;;
  548. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  549.  
  550. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  551.  
  552. ; EuLisp names which don't need renaming
  553.  
  554. (export 
  555.       <
  556.       <=
  557.       >
  558.       >=
  559.       =
  560.       +
  561.       -
  562.       *
  563.       /
  564.           abs 
  565.       and
  566.       append
  567.       apply
  568.       assoc
  569.       assq
  570.       asin
  571.       acos
  572.       atan
  573.       car
  574.       cdr
  575.       caar
  576.       cadr
  577.       cdar
  578.       cddr
  579.       caaar
  580.       caadr
  581.       cadar
  582.       caddr
  583.       cdaar
  584.       cdadr
  585.       cddar
  586.       cdddr
  587.       caaaar
  588.       caaadr
  589.       caadar
  590.       caaddr
  591.       cadaar
  592.       cadadr
  593.       caddar
  594.       cadddr
  595.       cdaaar
  596.       cdaadr
  597.       cdadar
  598.       cdaddr
  599.       cddaar
  600.       cddadr
  601.       cdddar
  602.       cddddr
  603.       ceiling
  604.       char-upcase
  605.       char-downcase
  606.       cond
  607.       cons
  608.       cos
  609.       exp
  610.       expt
  611.       denominator
  612.       floor
  613.           gcd
  614.       lcm
  615.       length
  616.       let
  617.       let*
  618.       list
  619.       list-ref
  620.       log
  621.       make-string
  622.       make-vector
  623.       max
  624.       min
  625.       member
  626.       memq
  627.       modulo
  628.       newline
  629.       not
  630.       numerator
  631.       or
  632.       peek-char
  633.       print
  634.       quasiquote
  635.       quotient
  636.       read
  637.       read-char
  638.       remainder
  639.       reverse
  640.       round
  641.       sin
  642.       string-copy
  643.       string-length
  644.       string-ref
  645.       tan
  646.       vector-length
  647.       vector-ref
  648.       write
  649. )
  650.  
  651. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  652.  
  653. ; EuLisp functions renamed to Scheme in this module
  654. ; NB This renaming can be done here, on export, but currently
  655. ; appears at the top of the file (as I don't know how to do it
  656. ; on export!)
  657.  
  658. (export
  659.     char?
  660.     char=?
  661.     char<?
  662.     char>?
  663.     char<=?
  664.     char>=?
  665.     char->integer
  666.     current-input-port
  667.     current-output-port
  668.     display
  669.     eof-object?
  670.     eq?
  671.     equal?
  672.     even?
  673.     input-port?
  674.     integer->char
  675.     last-pair
  676.     length
  677.     letrec
  678.     list->string
  679.     list->vector
  680.     map
  681.     null?
  682.     number?
  683.     number->string
  684.     odd?
  685.     output-port?
  686.     pair?
  687.     procedure?    
  688.     string?
  689.     string-append
  690.     string->list
  691.     string->symbol
  692.     substring
  693.     symbol?
  694.     symbol->string
  695.     vector?
  696.     vector->list
  697.     zero?
  698. )
  699.  
  700. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  701.  
  702. ; Scheme functions defined in this module
  703.  
  704. (export 
  705.     inc ; in place of 1+
  706.     dec ; in place of -1+
  707.  
  708.     begin 
  709.     boolean?
  710.     call-with-current-continuation
  711.     call-with-input-file
  712.     call-with-output-file
  713.     char-ready?
  714.     close-input-port 
  715.     close-output-port
  716.     complex?
  717.     cons-stream
  718.     define 
  719.     delay 
  720.         else    ; ho hum
  721.     empty-stream? 
  722.     error 
  723.     for-each
  724.     force
  725.     freeze
  726.     head 
  727.     integer? 
  728.     last-pair
  729.     list? 
  730.     ;load    this has to be in scheme module (to use eval/cm)
  731.     make-promise 
  732.     open-input-file 
  733.     open-output-file
  734.     rational?
  735.     real? 
  736.     set!     ; could be a renaming of setq if we could rename specials
  737.     set-car! 
  738.     set-cdr! 
  739.     sqrt    ; should this be in EuLisp?
  740.     string
  741.     string-set!
  742.     string->list
  743.     tail 
  744.     the-empty-stream
  745.     vector-set!
  746.     vector
  747.     with-input-from-file
  748.     with-output-to-file
  749. )
  750.  
  751. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  752.  
  753. ; Abelson and Sussman compatibility
  754.  
  755. ;(defun atom? (x) (not (pair? x))) 
  756. ; actually, V0.37 has atom but it ain't in EuLisp
  757. (defconstant atom? atom)
  758.  
  759. (defconstant princ display)
  760.  
  761. (export atom? princ print)
  762.  
  763. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  764.  
  765. ; Compatability with old Schemes
  766.  
  767. (defconstant prin1 write)
  768. (defconstant call/cc call-with-current-continuation)
  769. (defmacro sequence forms `(progn ,@forms))
  770.  
  771. (export prin1 call/cc sequence)
  772.  
  773. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  774.  
  775. ;; Real bozo hack at the number system...
  776.  
  777. (defun exact? (x) 
  778.   (cond
  779.     ((eq? (class-of x) integer) t)
  780.     ((eq? (class-of x) real) ())
  781.     (else ())))
  782.  
  783. (defun inexact? (x) 
  784.   (cond
  785.     ((eq? (class-of x) integer) ())
  786.     ((eq? (class-of x) real) t)
  787.     (else ())))
  788.  
  789. (defun exact->inexact (x) (* 1.0 x))
  790. (defun inexact->exact (x) (floor x))
  791.  
  792.  
  793. (export exact? inexact? positive? exact->inexact inexact->exact)
  794.  
  795. (defun write-char (c . port)
  796.   (feel-write-char c (if (null? port) (current-output-port) (car port))))
  797.  
  798. (export write-char)
  799.  
  800. (defun list-tail (l n)
  801.   (if (= n 0) l (list-tail (cdr l) (- n 1))))
  802.  
  803. (export list-tail)
  804.  
  805. (defun flush-output stuff
  806.   (flush (if (null? stuff) (current-output-port) (car stuff))))
  807.  
  808. (export flush-output)
  809.  
  810. (defun last-pair (l)
  811.   (cond
  812.     ((not (pair? l)) (error "last-pair: bogus arg dude!" clock-tick))
  813.     ((not (pair? (cdr l))) l)
  814.     (else (last-pair (cdr l)))))
  815.  
  816. ;; Hacks...
  817.  
  818. (defstruct <ovector> () 
  819.   ((vector initarg vector accessor ovector-vector))
  820.   constructor (make-ovector-obj vector)
  821.   predicate ovector?)
  822.  
  823. (define (ovector . stuff)
  824.   (make-ovector-obj (apply vector stuff)))
  825.  
  826. (define (make-ovector size init)
  827.   (make-ovector-obj (make-vector size init)))
  828.  
  829. (define (ovector-ref v i)
  830.   (vector-ref (ovector-vector v) i))
  831.  
  832. (define (ovector-set! v i val)
  833.   (vector-set! (ovector-vector v) i val)
  834.   val)
  835.  
  836. (export ovector? ovector make-ovector ovector-ref ovector-set!)
  837.  
  838. (defconstant $t t)
  839. (defconstant $f '())
  840.  
  841. (export $t $f)
  842.  
  843. )
  844. ; end of newschemedef.em
  845.